/**
 * @author ingvar
 * @version 1.0
 * @since 2/10/13
 */

import java.util.Scanner;
import java.util.Stack;

public class Interpreter {

    private Scanner scanner = new Scanner(System.in);
    private Stack<String> stack = new Stack<String>();
    public Interpreter(){

        while(scanner.hasNext()){
            String s  = scanner.nextLine();

            if(isNumber(s)){
                stack.push(s.substring(5));
            } else if(isOperator(s)){


                if(stack.size() < 2)
                    syntaxError();

                Integer number1 = Integer.parseInt(stack.pop());
                Integer number2 = Integer.parseInt(stack.pop());

                Integer result = s.compareTo("ADD") == 0 ? number1 + number2 : number1 * number2;

                stack.push(result.toString());

            } else if(s.equals("PRINT"))
                break;
            else
                syntaxError();

        }

        if(stack.isEmpty())
            syntaxError();

        System.out.println(stack.pop());
    }

    private boolean isNumber(String s){
        return s.matches("PUSH \\d+");
    }


    private boolean isOperator(String s){
        return s.equals("ADD") || s.equals("MULT");
    }

    public static void main(String[] args)  {
        new Interpreter();
    }

    private void syntaxError(){
        System.out.println("Syntax error!");
        System.exit(1);
    }
}
